<extend name="Common:common"/>
<block name="main">

    <div class="main-content">
        <div class="breadcrumbs" id="breadcrumbs">
            <script type="text/javascript">
                try {
                    ace.settings.check('breadcrumbs', 'fixed')
                } catch (e) {
                }
            </script>

            <ul class="breadcrumb">
                <li>
                    <i class="icon-home home-icon"></i>
                    <a href="#"> 云系统管理平台</a>
                </li>

                <li>
                    <a href="#">系统基本信息</a>
                </li>
                <li class="active">系统设置</li>
            </ul>
            <!-- .breadcrumb -->

            <div class="nav-search" id="nav-search">
                <a href="{:U('AdminUser/createadminuser')}" class="btn btn-xs btn-success"><i class="icon-plus icon-white"></i>添加新用户</a>
            </div>
            <!-- #nav-search -->
        </div>

        <div class="page-content">

            <div class="row">
                <form action="{:U('AdminUser/createadminuser')}" method="post"  class="form-horizontal" id="createfrom">
                    <div class="widget-content nopadding">
                        <form action="#" method="get" class="form-horizontal">
                            <div class="control-group">
                                <label class="control-label">用户名:</label>
                                <div class="controls">
                                    <input type="text" class="span2 username" placeholder="用户名" name="username" />
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label">密&nbsp;&nbsp;&nbsp;&nbsp;码:</label>
                                <div class="controls">
                                    <input type="password"  class="span2" placeholder="密码" name="password"  />
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label">选择用户组:</label>
                                <div class="controls">
                                    <select name="role_id" class="span2" >
                                        <volist name="role_list" id="vo">
                                            <option value="{$vo.id}">{$vo.name}</option>
                                        </volist>
                                    </select>
                                </div>
                            </div>
                            <div class="form-actions">
                                <button type="submit" class="btn btn-success">确认</button>
                            </div>
                        </form>
                    </div>
                </form>
            </div>
        </div><!-- /.page-content -->
    </div><!-- /.main-content -->

    <script src="__ROOT__/Application/Common/Public/js/jquery.validate-1.13.1.js"></script>
    <script type="text/javascript">
        var $URL = "__APP__/Home/AdminUser/";
        $(function(){
            //delete AdminUser
            $(".del").bind('click',function(){
                var $msg = confirm('确认删除该用户吗？删除后不可恢复！');
                var $id = $(this).attr('value');
                var $url = $URL+'delUser';
                if(!$msg){
                    return false;
                }
//            $.getJSON('$url',{user_id:$id},function(json){
//                if(json.status ==1 ){
//                    alert(1111);
//                }else{
//                    alert(000000);
//                }
//            });
                $.ajax({
                    url: $URL+'delUser',
                    type: 'get',
                    dataType: 'text',
                    data:{user_id:$id},
                    success:function($result){
                        if($result){
                            alert('删除成功');
                            window.location.reload();
                        }else{
                            alert('删除失败');
                        }
                    },
                    error:function(){
                        alert('删除失败');
                    }
                });
            });
            //status set
            $(".set").bind('click',function(){
                var $id = $(this).attr('value');
                $.ajax({
                    url: $URL+'setStatus',
                    type: 'get',
                    dataType: 'text',
                    data:{uid:$id},
                    success:function($result){
                        if($result){
                            alert('设置成功');
                            window.location.reload();
                        }else{
                            alert('设置失败');
                        }
                    },
                    error:function(){
                        alert('设置失败');
                    }
                });
            });
        });
    </script>
</block>

<!DOCTYPE html>
<html lang="en">
<head>
    <include file='Common:head'/>
</head>
<body>

<!--Header-part-->
<div id="header">
  <h1><a href="dashboard.html">旅游数据中心</a></h1>
</div>
<!--close-Header-part--> 


<!--top-Header-menu-->
<include file='Common:header_menu'/>
<!--close-top-Header-menu-->

<!--start-top-serch-->
<include file='Common:serch'/>
<!--close-top-serch-->

<!--sidebar-menu-->
<include file='Common:sidebar_menu'/>
<!--sidebar-menu-->

<!--main-container-part-->
<div id="content">
  <div id="content-header">
    <div id="breadcrumb"> <a href="#" title="Go to Home" class="tip-bottom"><i class="icon-home"></i>后台首页</a> <a href="{:U('AdminUser/index')}" class="current">平台用户管理</a> </div>
  </div>
  <div class="container-fluid">
    <div class="row-fluid">
      <div class="span12">
  
	    <div class="widget-box">
	        <div class="widget-title"> <span class="icon"> <i class="icon-align-justify"></i> </span>
	          <h5>创建新平台用户</h5>
	        </div>

	        <form action="{:U('AdminUser/createadminuser')}" method="post"  class="form-horizontal" id="createfrom">
	        <div class="widget-content nopadding">
	          <form action="#" method="get" class="form-horizontal">
	            <div class="control-group">
	              <label class="control-label">用户名:</label>
	              <div class="controls">
	                <input type="text" class="span2 username" placeholder="用户名" name="username" />
	              </div>
	            </div>
	            <div class="control-group">
	              <label class="control-label">密&nbsp;&nbsp;&nbsp;&nbsp;码:</label>
	              <div class="controls">
	                <input type="password"  class="span2" placeholder="密码" name="password"  />
	              </div>
	            </div>
	            <div class="control-group">
	              <label class="control-label">选择用户组:</label>
	              <div class="controls">
	                <select name="role_id" class="span2" >
	                	<volist name="role_list" id="vo">
	                 		 <option value="{$vo.id}">{$vo.name}</option>
	                 	</volist>
	                </select>
	              </div>
	            </div>
	            <div class="form-actions">
	              <button type="submit" class="btn btn-success">确认</button>
	            </div>
	          </form>
	        </div>
	        </form>

	      </div>

      </div>
    </div>
  </div>
</div>
<!--Footer-part-->
<include file='Common:footer'/>
<!--end-Footer-part-->
<script src="__ROOT__/Application/Common/Public/js/jquery.min.js"></script> 
<script src="__ROOT__/Application/Common/Public/js/jquery.ui.custom.js"></script> 
<script src="__ROOT__/Application/Common/Public/js/bootstrap.min.js"></script> 
<script src="__ROOT__/Application/Common/Public/js/jquery.uniform.js"></script> 
<script src="__ROOT__/Application/Common/Public/js/select2.min.js"></script> 
<script src="__ROOT__/Application/Common/Public/js/jquery.dataTables.min.js"></script> 
<script src="__ROOT__/Application/Common/Public/js/matrix.js"></script> 
<script src="__ROOT__/Application/Common/Public/js/matrix.tables.js"></script>
<script src="__ROOT__/Application/Common/Public/js/jquery.validate-1.13.1.js"></script>
</body>
</html>
<script type="text/javascript">
    var AJAXURL = "__APP__/Home/AdminUser/";
    $(document).ready(function (){
        $("#createfrom").validate({
            rules:{
                username: {
                    required: true,
                    //异步检测账号是否存在
                    remote:{
                        url : AJAXURL+'checkUser',
                        type: 'post',
                        dataType: 'json',
                        data:{
                            username:function(){
                                return $(".username").val();
                            }
                        }
                    }
                },
                password: {
                    required: true,
                    minlength: 6,
                    maxlength: 24
                }

            },
            messages: {
                username: {
                    required: '用户名不能为空',
                    minlength: '用户名不能小于6个字符',
                    maxlength: '用户名不能超过24个字符',
                    remote:    '用户名已经存在'
                },
                password: {
                    required: '密码不能为空',
                    minlength: '密码不能小于6个字符',
                    maxlength: '密码不能超过24个字符'
                }
            }
        });
        $.validator.addMethod("check_name", function(value, element, params){
            var str = /^[A-Za-z]+$/;
            return this.optional(element) || (str.test(value));
        }, "必须为英文字母组成");
        $.validator.addMethod("check_num", function(value, element, params){
            var str = /^\d+(\.\d+)?(\.\d+)?(\.\d+)?$/;
            return this.optional(element) || (str.test(value));
        }, "版本号格式不正确");
    });
</script>
